#include<iostream>
#include<vector>
#include <algorithm>
using namespace std;

class Solution {
public:
    vector<vector<int>> threeSum(vector<int>& nums) {
        vector<vector<int>> vv;

        sort(nums.begin(),nums.end());
        int cur=0,left,right;
        int n = nums.size();
        while(cur < n && nums[cur] <= 0)
        {
            left = cur + 1;
            right = n-1;
            int target = -nums[cur];

            while(left < right)
            {
                int sum = nums[left] + nums[right];
                if(target < sum) right--;
                else if(target > sum) left++;
                else
                {
                    vv.push_back({nums[cur],nums[left],nums[right]});
                    right--;
                    left++;

                    while(left < right && nums[right]==nums[right+1]) right--;
                    while(left < right && nums[left] == nums[left-1]) left++;
                }
            }

            cur++;
            while(cur < n && nums[cur - 1] == nums[cur]) cur++;
        }

        return vv;
    }
};

int main()
{

	return 0;
}
